package fun.hijklmn.magic.admin.server.controller;

import fun.hijklmn.magic.resource.client.api.ResourceUploadServiceApi;
import fun.hijklmn.magic.resource.common.transport.UploadFileResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Description
 * @Author fs
 * @Date 2021/5/26 21:34
 * @Version 0.0.1-SNAPSHOT
 **/
@Api(value = "图片管理后台接口", tags = "图片服务前端控制器")
@RestController
public class ImageUploadController {

    @Autowired
    private ResourceUploadServiceApi resourceUploadServiceApi;

    @ApiOperation(value = "上传图片", tags = "图片服务前端控制器")
    @PostMapping(value = "uploadFile", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    public UploadFileResponse uploadFile(@RequestParam("key") String key, @RequestParam("fileName") String fileName, @RequestPart("file") MultipartFile file) {
        return resourceUploadServiceApi.uploadFile(key, fileName, file);
    }

}
